(function(){
	var AjaxCrud = QualityCheck.AjaxCRUD;
	var serverUrl = QualityCheck.GPUD.ServiceConfig;
	$(function(){
		var usercode = $("#user-name",parent.parent.document).attr("code");
		var userkey = $("#user-name",parent.parent.document).attr("key");
		var usertype = $("#user-name",parent.parent.document).attr("usertype");
		keyCheck(usercode,usertype,userkey,function(){
			initSmPages();
			window.onresize = function () {
				initSmPages();
			};
			pagebtns();
		});
	});
	function pagebtns(){
		check("role-name",isNull,"null");
		$("#role-add").click(function(){
			if(checkUser()){
				addRole();
			}
		});
	}
	function addRole(){
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var params = {};
		var param = {};
		params["name"] = encodeURI($("#role-name").val());	
		//params["remark"] = encodeURI($("#role-remark").val());
		params["describe"] = encodeURI($("#role-describe").text());
		params["schoolcode"] = schoolcode;
		for(var key in params){
			if(params[key] != ""){
				param[key] = params[key];
			}
		}
		var data = {
				cmd:"insertRole",
				model:"license",
				userKey:userKey,
				data:param,
				remark:"",						
		};
		processBegin("正在添加中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				processEnd("添加角色成功");
			}else{
				processError("添加角色失败");
			}
		},null,null);	
	}
	
	function checkUser(){
		if($("#role-name").val() == ""){
			$("#role-name-ex").html("不能为空");
			return false; 
		}else{
			return true; 
		}
	}
	function initSmPages(){
		var rcH = $(".body-right",parent.document).height() - $(".right-title").height()-3;
		$(".right-content").height(rcH);
		
		var cdsH = $(".right-content").height() - $(".content-title").height() - 40;
		$(".content-data-show").height(cdsH);
	}
	
})();
